import request from "@/utils/request";

export function login(adminname: string, password: string) {
  return request<null, ApiResponse<AdminInfo>>({
    url: "/admin/admin/login",
    method: "POST",
    data: {
      adminname,
      password,
    },
  });
}

/**
 * 获取管理员列表数据
 */
export function getAdminList() {
  return request<null, ApiResponse<Array<AdminInfo2>>>({
    url: "/admin/admin/list",
    method: "GET",
  });
}

/**
 * 添加管理员
 */
export function addAdmin(
  adminname: string,
  password: string,
  role: number,
  checkedKeys: string[] = []
) {
  return request<null, ApiResponse>({
    url: "/admin/admin/add",
    method: "POST",
    data: {
      adminname,
      password,
      role,
      checkedKeys,
    },
  });
}

/**
 * 更新管理员
 */
export function updateAdmin(
  adminname: string,
  password: string,
  role: number,
  checkedKeys: string[] = []
) {
  return request<null, ApiResponse>({
    url: "/admin/admin/update",
    method: "POST",
    data: {
      adminname,
      password,
      role,
      checkedKeys,
    },
  });
}
